//index.js
//获取应用实例
var app = getApp();
var util = require('../../utils/util');
Page({
  data: {
    currentPage: 1
  },
  onShow: function () {
    var that = this;
  
  },
  onLoad: function () {
    var that=this;
    app.checkLogin(function () {
      that.setData({
        orderlist: [],
        date: util.formatTime(new Date)
      });
      that.getOrderTotal();
    })
    var pages = getCurrentPages();
  },
  //首页订单统计 列表
  getOrderTotal: function () {
    var that = this;
    util.showLoading();
    var apiUrl = '/api/dis/order/order_total';
    var apiData = {
      send_time: that.data.date,
      page:this.data.currentPage
    }
    util.fetchPost(apiUrl, apiData, function (res) {
      util.hideLoading();
      if (res.state == 1) {
          that.setData({
			  orderlist: res.datas.store_list,
            orderinfo:res.datas,
          });
      } else {
        util.message(res.datas);
      }
    });
  },
  //选择日期
  bindDateChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value,
      orderlist:[]
    })
    this.getOrderTotal()
  },
  //配送订单详情
  oNOrderDetilTap: function (e) {
    var index=e.currentTarget.dataset.index
    wx.navigateTo({
      url: '../orderDetil/orderDetil?store_id=' + this.data.orderlist[index].store_id + "&send_time=" + this.data.date,
    })
  },
  /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
  onPullDownRefresh: function () {
    var that = this;
    that.setData({
      orderinfo:[],
      currentPage:1
    })
    that.getOrderTotal()
  },
  /**
  * 页面上拉触底事件的处理函数
  */
  onReachBottom: function () {
    
  },
	//结算记录
	onDetailedTap() {
		wx.navigateTo({
			url: '../detailed/detailed'
		})
	},
})